﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Enterprise.Framework.Frame.Architecture;
using Resto.CostControl.Core.Query.SupplierModule.ViewObject;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.SupplierModule.QueryObject
{
    public class SupplierContractQO : IApplicationQueryObject
    {
        private IQueryable<SupplierContractVO> GetSupplierContractVOSet()
        {
            IEntityRepository<SupplierContract> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<SupplierContract>();

            IQueryable<SupplierContractVO> list = from o in repository.Objects
                                              select new SupplierContractVO()
                                              {
                                                  ID = o.ID,
                                                  Code = o.Code,
                                                  SupplierId = o.SupplierID,
                                                  BeginDate = o.BeginDate,
                                                  EndDate = o.EndDate,
                                              };

            return list;
        }

        public SupplierContractVO[] QuerySupplierContractVOByPager(ISpecification<SupplierContractVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<SupplierContractVO> list = GetSupplierContractVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<SupplierContractVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}


